//
//  AboutUIViewController.swift
//  ReferenceFunctionDemo
//
//  Created by MACBOOK on 2016/12/16.
//  Copyright © 2016年 刘袭锐. All rights reserved.
//

import UIKit

private let cellId = "cellId"


class AboutUIViewController: UIViewController,mappingable {

    
    /// 数据数组
    fileprivate lazy var dataArr : [String] = {
        let dataArr = ["图片轮播","美颜GPUImage"]
        return dataArr
    }()
    
    /// 控制器数组
    fileprivate lazy var classNames : [String] = {
        let classNames = ["PictureController","GPUImageController"]
        return classNames
    }()
    
    
    
    
    /// tableView展示
    fileprivate lazy var tableView : UITableView = {
        let tableView = UITableView(frame: self.view.bounds, style: .plain)
        tableView.dataSource = self
        tableView.delegate = self
        return tableView
    }()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        
        //设置UI
        setupUI()
    }
}


// MARK: - 设置UI
extension AboutUIViewController{
    
    fileprivate func setupUI(){
        view.addSubview(tableView)
    }
}


// MARK: - 数据源
extension AboutUIViewController : UITableViewDataSource{
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataArr.count
    }
    
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: cellId)
        
        if cell == nil {
            cell = UITableViewCell(style: .default, reuseIdentifier: cellId)
        }
        
        cell?.textLabel?.text = dataArr[indexPath.row]
        
        return cell!
    }
}
// MARK: - 代理
extension AboutUIViewController : UITableViewDelegate{
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        // 1. 取出对应的控制器名称
        let className = classNames[indexPath.row]
        // 2. 创建对应的视图
        let vc = mappingableGetViewController(className)
        vc.title = dataArr[indexPath.row]
        navigationController?.pushViewController(vc, animated: true)
    }
}


